package com.tiza.xiaoyoubao.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mapple on 17/3/1.
 * <p>
 * 特别任务未完成
 */

public class TbUnComplateFragment extends BaseFragment {

    @BindView(R.id.tv_sort1)
    TextView tv_sort1;
    @BindView(R.id.tv_sort2)
    TextView tv_sort2;
    @BindView(R.id.tv_sort3)
    TextView tv_sort3;
    @BindView(R.id.tv_sort4)
    TextView tv_sort4;
    @BindView(R.id.tv_selectline1)
    TextView tv_selectline1;
    @BindView(R.id.tv_selectline2)
    TextView tv_selectline2;
    @BindView(R.id.tv_selectline3)
    TextView tv_selectline3;
    @BindView(R.id.tv_selectline4)
    TextView tv_selectline4;
    private static FragmentManager fm;
    Bundle args;
    public String way;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_advances_uncomplate;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        fm = getFragmentManager();
        args=getArguments();
        way=args.getString("way");
        if(way.equals("1")){
            tv_sort1.setTextColor(getResources().getColor(R.color.steel_blue));
            tv_selectline1.setVisibility(View.VISIBLE);
            tv_selectline1.setBackgroundColor(getResources().getColor(R.color.steel_blue));
            showFragment(new TbOperateFragment());
        }else if(way.equals("2")){
            tv_sort2.setTextColor(getResources().getColor(R.color.steel_blue));
            tv_selectline2.setVisibility(View.VISIBLE);
            tv_selectline2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
            showFragment(new TbRebatesFragment());
        }else if(way.equals("3")){
            tv_sort3.setTextColor(getResources().getColor(R.color.steel_blue));
            tv_selectline3.setVisibility(View.VISIBLE);
            tv_selectline3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
            showFragment(new TbShipmentsFragment());
        }else if(way.equals("4")){
            tv_sort4.setTextColor(getResources().getColor(R.color.steel_blue));
            tv_selectline4.setVisibility(View.VISIBLE);
            tv_selectline4.setBackgroundColor(getResources().getColor(R.color.steel_blue));
            showFragment(new TbAllFragment());
        }
    }

    public void resetTabsStatus() {
        tv_sort1.setTextColor(getResources().getColor(R.color.black));
        tv_sort2.setTextColor(getResources().getColor(R.color.black));
        tv_sort3.setTextColor(getResources().getColor(R.color.black));
        tv_sort4.setTextColor(getResources().getColor(R.color.black));
        tv_selectline1.setVisibility(View.INVISIBLE);
        tv_selectline2.setVisibility(View.INVISIBLE);
        tv_selectline3.setVisibility(View.INVISIBLE);
        tv_selectline4.setVisibility(View.INVISIBLE);
        tv_selectline1.setBackgroundColor(getResources().getColor(R.color.black));
        tv_selectline2.setBackgroundColor(getResources().getColor(R.color.black));
        tv_selectline3.setBackgroundColor(getResources().getColor(R.color.black));
        tv_selectline4.setBackgroundColor(getResources().getColor(R.color.black));
    }

    @OnClick({R.id.view_sort1, R.id.view_sort2, R.id.view_sort3, R.id.view_sort4})
    public void onClick(View view) {
        resetTabsStatus();
        switch (view.getId()) {
            case R.id.view_sort1:
                tv_sort1.setTextColor(getResources().getColor(R.color.steel_blue));
                tv_selectline1.setVisibility(View.VISIBLE);
                tv_selectline1.setBackgroundColor(getResources().getColor(R.color.steel_blue));
                showFragment(new TbOperateFragment());
                break;
            case R.id.view_sort2:
                tv_sort2.setTextColor(getResources().getColor(R.color.steel_blue));
                tv_selectline2.setVisibility(View.VISIBLE);
                tv_selectline2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
                showFragment(new TbRebatesFragment());
                break;
            case R.id.view_sort3:
                tv_sort3.setTextColor(getResources().getColor(R.color.steel_blue));
                tv_selectline3.setVisibility(View.VISIBLE);
                tv_selectline3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
                showFragment(new TbShipmentsFragment());
                break;
            case R.id.view_sort4:
                tv_sort4.setTextColor(getResources().getColor(R.color.steel_blue));
                tv_selectline4.setVisibility(View.VISIBLE);
                tv_selectline4.setBackgroundColor(getResources().getColor(R.color.steel_blue));
                showFragment(new TbAllFragment());
                break;
        }
    }

    public static void showFragment(Fragment fragment) {
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.fl_content, fragment);
        transaction.commit();
    }
}
